package model.textChat;

import java.io.Serializable;
import java.util.ArrayList;

public class MessageRecorder implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ArrayList<Message> records;
	private int pointer = 1;
	
	public MessageRecorder()
	{
		records = new ArrayList<Message>();
	}
	
	public void append(Message message)
	{
		records.add( message );
	}
	
	public Message readNextRecord()
	{
		int numOfRecords = records.size();
		if ( pointer > numOfRecords )
		{
			return null;
		}
		
		Message message = records.get( numOfRecords - pointer );
		pointer++;
		
		return message;
	}
	
	public void reset()
	{
		pointer = 1;
	}
}
